from javax.swing import *
import java
from com.nexes.wizard import *
from WinApp import PyAction

class GenericDescriptor(WizardPanelDescriptor):
	IDENTIFIER = None;
	mypanel = None
	prevpanel = None
	nextpanel = None
	def __init__(self,name,mypanel,prevpanel,nextpanel):
		self.IDENTIFIER=name
		self.mypanel = mypanel
		if nextpanel is None:
			pass
		else:
			self.nextpanel = nextpanel
		
		if prevpanel is None:
			pass
		else:
			self.prevpanel = prevpanel
		#function
		self.aboutToDisplayPanel = mypanel.aboutToDisplayPanel
		WizardPanelDescriptor(java.lang.String(self.IDENTIFIER),self.mypanel);
		self.setPanelComponent(self.mypanel)

	def getNextPanelDescriptor(self):
		if self.nextpanel is None:
			return None
		return self.nextpanel.IDENTIFIER;

	def getBackPanelDescriptor(self):
		if self.prevpanel is None:
			return None
		return self.prevpanel.IDENTIFIER;

	def getPanelComponent(self):
		return self.mypanel

class SelectOrgPanel(JPanel):
	IDENTIFIER = "ORGANISM"
	contentPanel = None
	def __init__(self):
		self.contentPanel = self.createPanel();
	        self.setLayout(java.awt.BorderLayout());
		self.add(self.contentPanel,java.awt.BorderLayout.SOUTH);
		self.setSize(100,100)

	def createPanel(self):
		me = JPanel()
	        me.setLayout(java.awt.BorderLayout());

		titleLabel = JLabel('Welcome to the NCA Data Import Wizard')
		iconLabel = JLabel('Choose the Organism You want to Analyze with NCA');
		jc = JComboBox(['Ecoli','Yeast','Human','Mouse'])

		me.add(titleLabel,java.awt.BorderLayout.NORTH);
		me.add(iconLabel);
		me.add(jc,java.awt.BorderLayout.SOUTH);
		return me

	def aboutToDisplayPanel(self):
		self.getWizard().setNextFinishButtonEnabled(False);
		self.getWizard().setBackButtonEnabled(False);



   
class LoadArrayDataPanel(JPanel):
	IDENTIFIER = "MICROARRAY"
	hook=None
	def __init__(self,fhook):
		self.hook = fhook
		self.contentPanel = self.createPanel()
	        self.setLayout(java.awt.BorderLayout());
		self.add(self.contentPanel)
		
		
	def createPanel(self):
		mPanel = JPanel()
		mPanel.setLayout(java.awt.BorderLayout())
		iconLabel = JLabel('Microarray Data Source')
		mb = JButton('Load Array Data from File')
		mb.addActionListener( PyAction( self.hook, self.hook, None, mb))
		# have filereader chk the results
		mPanel.add(iconLabel,java.awt.BorderLayout.NORTH);
		mPanel.add(mb)
		return mPanel
	
	def aboutToDisplayPanel(self):
		self.getWizard().setNextFinishButtonEnabled(False);
		self.getWizard().setBackButtonEnabled(True);

class RatioBuilderPanel(JPanel):
	IDENTIFIER = "RATIOBUILDER"
	hook=None
	def __init__(self,fhook):
		#print 'here'
		self.hook = fhook
		#print 'after hool'
	        self.setLayout(java.awt.BorderLayout());
		#print 'after layout'
		contentPanel = self.createPanel()	
		#print 'after content'
		self.add(contentPanel)
		#print 'after add'
	def aboutToDisplayPanel(self):
		self.getWizard().setNextFinishButtonEnabled(False);
		self.getWizard().setBackButtonEnabled(True);
	def createPanel(self):
		mPanel = JPanel()
		mPanel.setLayout(java.awt.BorderLayout())
		iconLabel = JLabel('RatioBuilder')
		mb = JButton('Load Ratios')
		print 'before hookset'
		mb.addActionListener( PyAction( self.hook, self.hook, None, mb))
		mPanel.add(iconLabel,java.awt.BorderLayout.NORTH);
		mPanel.add(mb)
		return mPanel
		

class IdConvertPanel(JPanel):
	IDENTIFIER = "IDCONVERT"
	def __init__(self,hook):
		iconLabel = JLabel('Convert ProbeSet Identifiers to Gene Symbol/Annotations');
		
		# check database, load in the keys, and an example entry for Elabel[0]
		
		contentPanel = JEditorPane();
	        self.setLayout(java.awt.BorderLayout());
	def aboutToDisplayPanel(self):
		self.getWizard().setNextFinishButtonEnabled(False);
		self.getWizard().setBackButtonEnabled(True);




class SelectTFsPanel(JPanel):
	IDENTIFIER = "SELECTTFS"
	def __init__(self,hook):
		iconLabel = JLabel('test');
		contentPanel = JEditorPane();
	        self.setLayout(java.awt.BorderLayout());
	def aboutToDisplayPanel(self):
		self.getWizard().setNextFinishButtonEnabled(False);
		self.getWizard().setBackButtonEnabled(True);

class NCAPanel(JPanel):
	IDENTIFIER = "NCA"
	def __init__(self,hook):
		iconLabel = JLabel('tsest');
		contentPanel = JEditorPane();
	        self.setLayout(java.awt.BorderLayout());
	def aboutToDisplayPanel(self):
		self.getWizard().setNextFinishButtonEnabled(True);
		self.getWizard().setBackButtonEnabled(True);


def WizBang(hook):
	orgP = SelectOrgPanel()
	arrayP=LoadArrayDataPanel(hook['array'])
	ratioP=RatioBuilderPanel(hook['ratio'])
	selectP=SelectTFsPanel(hook['select'])
	ncaP=NCAPanel(hook['nca'])
	wizard = Wizard();
	wizard.getDialog().setTitle("NCA Wizard");
	descriptor1 = GenericDescriptor("ORGANISM",orgP,None,arrayP);
	descriptor2 = GenericDescriptor("MICROARRAY",arrayP,orgP,ratioP);
	descriptor3 = GenericDescriptor("RATIOBUILDER",ratioP,arrayP,selectP);
	descriptor4 = GenericDescriptor("SELECTTFS",selectP,ratioP,ncaP);
	descriptor5 = GenericDescriptor("NCA",ncaP,selectP,None);
	wizard.registerWizardPanel(descriptor1.IDENTIFIER, descriptor1);
	wizard.registerWizardPanel(descriptor2.IDENTIFIER,descriptor2);
	wizard.registerWizardPanel(descriptor3.IDENTIFIER, descriptor3);
	wizard.registerWizardPanel(descriptor4.IDENTIFIER, descriptor4);
	wizard.registerWizardPanel(descriptor5.IDENTIFIER, descriptor5);
	wizard.setCurrentPanel(descriptor1.IDENTIFIER);
	return wizard